﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Data;
using System.Globalization;

namespace Curling
{
    public class ScoreConvertor : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            string[] player_index = parameter.ToString().Split(';');
            int player = Int32.Parse(player_index[0]);
            int index = Int32.Parse(player_index[1]);

            int?[][] Scores = (int?[][])value;

            if (Scores[0][index].HasValue && Scores[1][index].HasValue)
            {
                if (Scores[0][index].Value == Scores[1][index].Value)
                    return "x";

                return Scores[player][index].Value;
            }
            else
            {
                return "";
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return null;
        }
    }
}
